<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Enterprises extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	
	//-----------LOGIN & LOGOUT----------------------------------------------
	
	public function login(){
		$this->load->model('dpcmodel');
		$pTabSelection="";
		$displayData['pTabSelection']=$pTabSelection;
		$this->load->view('enterprises/login', $displayData);
	}
	
	public function logOut(){
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="";
		$displayData['pTabSelection']=$pTabSelection;
		$array_items = array('username' => '', 'logged_in' => '');
		$this->session->unset_userdata($array_items);
		$this->load->view('enterprises/logOut', $displayData);
	}
	
	public function authenticate(){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$username=$this->enterprisesmodel->authenticate($_POST);
		error_log("auth.............................".print_r($_POST, true));
		//var_dump($username);
		if (isset($username[0]['user_username']) && $_POST['username']==$username[0]['user_username']){
			$newdata = array(
					'user_id'  => $username[0]['user_id'],
					'username'  => $username[0]['user_username'],
					'user_permissions'  => $username[0]['user_permissions'],
					'logged_in' => TRUE
			);
			$this->session->set_userdata($newdata);
			$sessionUserData = $this->session->all_userdata();
		}else {
			$array_items = array('user_id' => '', 'username' => '', 'user_permissions' => '', 'logged_in' => '');
			$this->session->unset_userdata($array_items);
		}
		$pTabSelection="";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/welcome', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	//------------------ADD,DELETE,EDIT USERS-------------------------------------------
	
	public function addUser(){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="addUser";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['allUsersArray']=$this->enterprisesmodel->getAllUsers();
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/addUser', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function insertUser(){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="addUser";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allUsersArray']=$this->enterprisesmodel->insertUser($_POST);
			$displayData['allUsersArray']=$this->enterprisesmodel->getAllUsers();
			$this->load->view('enterprises/addUser', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function deleteUser($userId){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="addUser";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$this->enterprisesmodel->deleteUser($userId);
			$displayData['allUsersArray']=$this->enterprisesmodel->getAllUsers();
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/addUser', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function editUserPerm(){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="editUserPerm";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['allUsersArray']=$this->enterprisesmodel->getAllUsers();
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/editUserPerm', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function editUserPermission($userId){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="editUserPerm";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['userId']=$userId;
		$displayData['allUsersArray']=$this->enterprisesmodel->getAllUsers();
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/editUserPermission', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function updatePermissions(){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		//error_log("update permissions".print_r($_POST, true));
		$pTabSelection="editUserPerm";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['allUsersArray']=$this->enterprisesmodel->getAllUsers();
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->enterprisesmodel->updatePermissions($_POST);
			$this->load->view('enterprises/editUserPerm', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	//-------------add, edit, delete category------------------------------
	
	public function CategoryCMS(){
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="CategoryCMS";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['parentCat'] = $this->dpcmodel->getParentCategories();
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/CategoryCMS', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function addCategory(){
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="viewCategory";
		$displayData['pTabSelection']=$pTabSelection;
		$_POST['files'] = $_FILES;
		$this->enterprisesmodel->addCategory($_POST);
		$categoryArray=$this->enterprisesmodel->getAllCategories();
		$displayData['categoryArray']=$categoryArray;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewCategory', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function editCategory($category_id){
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="viewCategory";
		$displayData['pTabSelection']=$pTabSelection;
		$categoryDetailsArray=$this->enterprisesmodel->getCategoryDetails($category_id);
		$displayData['categoryDetailsArray']=$categoryDetailsArray;
		$displayData['parentCat'] = $this->dpcmodel->getParentCategories();
		$displayData['category_id']=$category_id;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/updateCategory', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function updateCategory(){
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="viewCategory";
		$displayData['pTabSelection']=$pTabSelection;
		$_POST['files'] = $_FILES;
		$this->enterprisesmodel->updateCategory($_POST);
		$categoryArray=$this->enterprisesmodel->getAllCategories();
		$displayData['categoryArray']=$categoryArray;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewCategory', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function getCategory(){
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="viewCategory";
		$displayData['pTabSelection']=$pTabSelection;
		$categoryArray=$this->enterprisesmodel->getAllCategories();
		$displayData['categoryArray']=$categoryArray;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewCategory', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function addStore(){
		//error_log("add store **** controller ".print_r($_POST, true));
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="";
		$_POST['files']=$_FILES;
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$store_id=$this->enterprisesmodel->addStore($_POST);
			$_POST['store_id']=$store_id;
			$storesArray=$this->enterprisesmodel->getAllStores();
			$displayData['storeArray']=$storesArray;
			$displayData['storeDetailsArray']=$storesArray;
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['rej'] = 'no';
			$this->load->view('enterprises/viewStore', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function editStore($store_id){
		error_log("inside editStore....");
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewStore";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['store_id']=$store_id;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$storeDetailsArray=$this->enterprisesmodel->getStoreDetails($store_id);
			$displayData['storeCategoriesArray']=$this->enterprisesmodel->getStoreCategories($store_id);
			$displayData['storeDetailsArray']=$storeDetailsArray;
			$storeArray=$this->enterprisesmodel->getAllstores();
			$displayData['storeArray']=$storeArray;
			$displayData['tagCloud'] = $this->enterprisesmodel->getTagCloud($store_id);
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allCategoriesArray']=$this->enterprisesmodel->getAllCategories();
			$displayData['rej'] = 'no';
			$this->load->view('enterprises/updateStore', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function updateStore(){
		error_log("inside updateStore.......");
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$_POST['files']=$_FILES;
		$pTabSelection="viewStore";
		$displayData['pTabSelection']=$pTabSelection;
		$this->enterprisesmodel->updateStore($_POST);
		$displayData['storeArray']=$this->dpcmodel->getAlphaStores($alpha='0-9');
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['rej'] = 'no';
			$this->load->view('enterprises/viewStore', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function rejectStore(){
		error_log("inside updateStore.......");
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$_POST['files']=$_FILES;
		$pTabSelection="viewStore";
		$displayData['pTabSelection']=$pTabSelection;
		$this->enterprisesmodel->rejectStore($_POST);
		$displayData['storeArray']=$this->enterprisesmodel->getProcessStores();
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$this->load->view('enterprises/reviewStores', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function verifyStore(){
		error_log("inside updateStore.......");
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$_POST['files']=$_FILES;
		$pTabSelection="viewStore";
		$displayData['pTabSelection']=$pTabSelection;
		$this->enterprisesmodel->vefifyStore($_POST);
		$displayData['storeArray']=$this->enterprisesmodel->getProcessStores();
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$this->load->view('enterprises/reviewStores', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function getStoresBy($alpha){
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="viewStore";
		$displayData['pTabSelection']=$pTabSelection;
		if($alpha=='rejected'){
			$displayData['storeArray']=$this->enterprisesmodel->getRejectedStores();
			$displayData['rej'] = 'yes';
		}else{
			$displayData['storeArray']=$this->dpcmodel->getAlphaStores('0-9');
			$displayData['rej'] = 'no';
		}
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$this->load->view('enterprises/viewStore', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function getStore($alpha){
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="viewStore";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['storeArray']=$this->dpcmodel->getAlphaStores($alpha);
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$displayData['rej'] = 'no';
			$this->load->view('enterprises/viewStore', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function reviewStores(){
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="viewStore";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['storeArray']=$this->enterprisesmodel->getProcessStores();
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$this->load->view('enterprises/reviewStores', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function StoreCMS(){
		//error_log("inside StoreCMS.......");
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="StoreCMS";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$displayData['allCategoriesArray']=$this->enterprisesmodel->getAllCategories();
			$this->load->view('enterprises/StoreCMS', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function CouponCMS()
	{
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="CouponCMS";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		$displayData['allStoresArray']=$this->enterprisesmodel->getStoresForCpn();
		$displayData['allCategoriesArray']=$this->enterprisesmodel->getAllCategories();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/CouponCMS', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function addCoupon(){
		//error_log("add code **** controller ".print_r($_POST, true));
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewCoupon";
		$_POST['files']=$_FILES;
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$_POST['user_id'] = $sessionUserData['user_id'];
			$sId = $_POST['code_store'][0];
			$_POST['store_detail'] = $this->enterprisesmodel->getStoreDetails($sId);
			$_POST['files'] = $_FILES;
			//var_dump($_POST);die();
			$this->enterprisesmodel->addCoupon($_POST);
			$displayData['allStoresArray']=$this->enterprisesmodel->getStoresForCpn();
			$storeId=$_POST['code_store']['0'];
			$displayData['storeId']=$storeId;
			$couponArray=$this->dpcmodel->getStoreCouponsCMS($storeId);
			$displayData['couponArray']=$couponArray;
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['cpnBy'] = 'store';
			$this->load->view('enterprises/viewCoupon', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function getCoupon($cpnBy,$storeId=0){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewCoupon";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		$userId = $sessionUserData['user_id'];
		if($cpnBy=='rejected'){
			$displayData['storeId']=$storeId;
			$couponArray=$this->enterprisesmodel->getStoreCoupons($cpnBy,$storeId,$userId);
			$displayData['rejectArray']=$couponArray;
			$displayData['cpnBy'] = $cpnBy;
		}elseif ($cpnBy=='store'){
			$displayData['allStoresArray']=$this->enterprisesmodel->getStoresForCpn();
			if(!isset($storeId) || $storeId==0){
				$storeId=$displayData['allStoresArray'][0]['store_id'];
			}
			$displayData['storeId']=$storeId;
			$couponArray=$this->enterprisesmodel->getStoreCoupons($cpnBy,$storeId,$userId);
			$displayData['couponArray']=$couponArray;
			$displayData['cpnBy'] = $cpnBy;
		}
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewCoupon', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function editCoupon($coupon_id){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewHotel";
		$displayData['pTabSelection']=$pTabSelection;
		$CouponDetailsArray=$this->enterprisesmodel->getCouponDetails($coupon_id);
		$displayData['couponDetailsArray']=$CouponDetailsArray;
		$displayData['coupon_id']=$coupon_id;
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$couponArray=$this->enterprisesmodel->getAllCoupons();
			$displayData['couponStoresArray']=$this->dpcmodel->getCouponStores($coupon_id);
			$displayData['allStoresArray']=$this->enterprisesmodel->getStoresForCpn();
			$displayData['allCategoriesArray']=$this->enterprisesmodel->getAllCategories();
			$displayData['couponArray']=$couponArray;
			$this->load->view('enterprises/updateCoupon', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function updateCoupon(){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		$_POST['user_id'] = $sessionUserData['user_id'];
		$sId = $_POST['code_store'][0];
		$_POST['store_detail'] = $this->dpcmodel->getStoreDetails($sId);
		$_POST['files'] = $_FILES;
		$this->enterprisesmodel->updateCoupon($_POST);
		$displayData['allStoresArray']=$this->enterprisesmodel->getStoresForCpn();
		$displayData['storeId']=$sId;
		$couponArray=$this->dpcmodel->getStoreCouponsCMS($sId);
		$displayData['couponArray']=$couponArray;
		$displayData['cpnBy'] = 'store';
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewCoupon', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function reviewCoupon(){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="reviewCoupon";
		$displayData['pTabSelection']=$pTabSelection;
		$couponArray=$this->enterprisesmodel->getReviewCoupons();
		$displayData['couponArray']=$couponArray;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/reviewCoupon', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function verifyCoupon($cId){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="reviewCoupon";
		$displayData['pTabSelection']=$pTabSelection;
		$this->enterprisesmodel->verifyCoupon($cId);
		$couponArray=$this->enterprisesmodel->getReviewCoupons();
		$displayData['couponArray']=$couponArray;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/reviewCoupon', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function declineCoupon($cId){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="reviewCoupon";
		$displayData['pTabSelection']=$pTabSelection;
		$this->enterprisesmodel->declineCoupon($cId);
		$couponArray=$this->enterprisesmodel->getReviewCoupons();
		$displayData['couponArray']=$couponArray;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/reviewCoupon', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function rejectCoupon($cId){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="reviewCoupon";
		$displayData['pTabSelection']=$pTabSelection;
		$this->enterprisesmodel->rejectCoupon($cId);
		$couponArray=$this->enterprisesmodel->getReviewCoupons();
		$displayData['couponArray']=$couponArray;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/reviewCoupon', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function BannerCMS(){
		error_log("inside BannerCMS.......");
		$this->load->model('enterprisesmodel');
		$this->load->model('dpcmodel');
		$this->load->library('session');
		$pTabSelection="bannerCMS";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$displayData['allCategoriesArray']=$this->enterprisesmodel->getAllCategories();
			$this->load->view('enterprises/BannerCMS', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function addBanner(){
		error_log("add code **** controller ".print_r($_POST, true));
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewBanner";
		$displayData['pTabSelection']=$pTabSelection;
		$_POST['files']=$_FILES;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$this->enterprisesmodel->addBanner($_POST);
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$storeId=$_POST['banner_store_id'];
			$displayData['storeId']=$storeId;
			$bannerArray=$this->dpcmodel->getStoreBanners($storeId);
			$displayData['bannerArray']=$bannerArray;
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewBanner', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function getBanner($storeId=0){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewBanner";
		$displayData['pTabSelection']=$pTabSelection;
		$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
		if(!isset($storeId) || $storeId==0){
			$storeId=$displayData['allStoresArray'][0]['store_id'];
		}
		$displayData['storeId']=$storeId;
		$bannerArray=$this->dpcmodel->getStoreBanners($storeId);
		$displayData['bannerArray']=$bannerArray;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewBanner', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function editBanner($banner_id){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewBanner";
		$displayData['pTabSelection']=$pTabSelection;
		$bannerDetailsArray=$this->enterprisesmodel->getBannerDetails($banner_id);
		$displayData['bannerDetailsArray']=$bannerDetailsArray;
		$store_id=$bannerDetailsArray[0]['banner_store_id'];
		$displayData['storeId']=$store_id;
		$displayData['banner_id']=$banner_id;
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$displayData['allCategoriesArray']=$this->enterprisesmodel->getAllCategories();
			$this->load->view('enterprises/updateBanner', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function updateBanner(){
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="";
		$displayData['pTabSelection']=$pTabSelection;
		$_POST['files']=$_FILES;
		$this->enterprisesmodel->updateBanner($_POST);
		$storeId=$_POST['banner_store_id'];
		$bannerArray=$this->dpcmodel->getStoreBanners($storeId);
		$displayData['bannerArray']=$bannerArray;
		$sessionUserData = $this->session->all_userdata();
		$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
		$displayData['storeId']=$storeId;
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewBanner', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function DetailCMS()
	{
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="DetailCMS";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
		$displayData['allCategoriesArray']=$this->enterprisesmodel->getAllCategories();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/DetailCMS', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function detailpage(){
	
		error_log("add code **** controller ".print_r($_POST, true));
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewDeals";
		$_POST['files']=$_FILES;
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$_POST['files'] = $_FILES;
			//var_dump($_POST);die();
			$this->enterprisesmodel->detailpage($_POST);
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$couponArray=$this->enterprisesmodel->getDeals();
			$displayData['couponArray']=$couponArray;
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewDeals', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function viewDeals(){
	
		error_log("add code **** controller ".print_r($_POST, true));
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewDeals";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$couponArray=$this->enterprisesmodel->getDeals();
			$displayData['couponArray']=$couponArray;
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewDeal', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function getDeals($dealId){
	
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewDeals";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$couponArray=$this->enterprisesmodel->getDealById($dealId);
			$displayData['couponArray']=$couponArray;
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/updateDeal', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function updateDeal(){
	
		error_log("add code **** controller ".print_r($_POST, true));
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewDeals";
		$_POST['files']=$_FILES;
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$this->enterprisesmodel->updateDeal($_POST);
			$displayData['allStoresArray']=$this->enterprisesmodel->getAllStores();
			$couponArray=$this->enterprisesmodel->getDeals();
			$displayData['couponArray']=$couponArray;
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewDeal', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function homeBannerCMS()
	{
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="bannerCMS1";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/homebannerCMS', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function addHomeBanner()
	{
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="bannerCMS1";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		$_POST['files'] = $_FILES;
		$this->enterprisesmodel->insertHomeBanner($_POST);
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['bannerArray'] = $this->enterprisesmodel->getAllHomeBanner();
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewHomebanner', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function viewHomeBanners()
	{
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewBanner1";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['bannerArray'] = $this->enterprisesmodel->getAllHomeBanner();
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewHomebanner', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function editHomeBanners($bId)
	{
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewBanner1";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['bannerDetailsArray'] = $this->enterprisesmodel->getHomeBannerById($bId);
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/updateHomeBanner', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
	
	public function updateHomeBanner()
	{
		$this->load->model('dpcmodel');
		$this->load->model('enterprisesmodel');
		$this->load->library('session');
		$pTabSelection="viewBanner1";
		$displayData['pTabSelection']=$pTabSelection;
		$sessionUserData = $this->session->all_userdata();
		$_POST['files'] = $_FILES;
		$this->enterprisesmodel->updateHomeBanner($_POST);
		if(isset($sessionUserData['logged_in']) && $sessionUserData['logged_in']){
			$displayData['bannerArray'] = $this->enterprisesmodel->getAllHomeBanner();
			$displayData['sessionUserData']=$sessionUserData;
			$this->load->view('enterprises/viewHomebanner', $displayData);
		}else {
			$this->load->view('enterprises/logOut', $displayData);
		}
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
